package com.octo.poker.data;

/**
 * Two cards are equal if their values are equal.
 */
public class Card {
	private CardValue cardValue;
	private CardColor cardColor;

	public Card(CardValue cardValue, CardColor cardColor) {
		this.cardValue = cardValue;
		this.cardColor = cardColor;
	}

	public CardValue getCardValue() {
		return cardValue;
	}

	public CardColor getCardColor() {
		return cardColor;
	}

	@Override
	public String toString() {
		return cardValue + " " + cardColor;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((cardColor == null) ? 0 : cardColor.hashCode());
		result = prime * result + ((cardValue == null) ? 0 : cardValue.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Card)) {
			return false;
		}
		Card other = (Card) obj;
		if (cardColor != other.cardColor) {
			return false;
		}
		if (cardValue != other.cardValue) {
			return false;
		}
		return true;
	}


	public static Card parse(String s) {
		return new Card(CardValue.parse(s.substring(0, s.length() - 1)), CardColor.parse(s.substring(s.length() - 1)));
	}

}
